<?php

namespace App\Admin\Controllers;

use App\Models\MemberPrices;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class MemberPriceController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '会员价格设置';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new MemberPrices);

        $grid->column('id', __('Id'));
        $grid->column('title', __('标题'));
        $grid->column('desc', __('标书'));
        $grid->column('original_price', __('原价（分）'));
        $grid->column('current_price', __('现价（分）'));
        $grid->column('type', __('类型'));
        $grid->column('sort', __('排序'));
        $grid->column('created_at', __('添加时间'));
        $grid->column('updated_at', __('更新'));

        $grid->actions(function (Grid\Displayers\Actions $actions){
            $actions->disableDelete();
            $actions->disableView();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(MemberPrices::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title', __('Title'));
        $show->field('desc', __('Desc'));
        $show->field('original_price', __('Original price'));
        $show->field('current_price', __('Current price'));
        $show->field('type', __('Type'));
        $show->field('sort', __('Sort'));
        $show->field('created_at', __('添加时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new MemberPrices);

        $form->text('title', __('标题'));
        $form->text('desc', __('描述'));
        $form->number('original_price', __('原价（分）'));
        $form->number('current_price', __('现价（分）'));
        $form->radio('type', __('类型'))->options(MemberPrices::$typeLabels)->default(3);
        $form->number('sort', __('排序'))->default(0);

        return $form;
    }
}
